package com.designpatterns.creational.prototype.deepclone.prototypeManager;

import java.util.Hashtable;
import java.util.Optional;

public class PrototypeManager {
    private Hashtable prototypeTable = new Hashtable();

    public PrototypeManager(){
        prototypeTable.put("A",new ConcretePrototypeA());
        prototypeTable.put("B",new ConcretePrototypeB());
    }

    public void add(String key,Prototype prototype){
        prototypeTable.put(key,prototype);
    }

    public Prototype get(String key){
        return Optional.ofNullable(((Prototype)prototypeTable.get(key)).clone()).orElse(null);
    }
}
